<template>
	<div class="app-container">
		<TopInfo />

		<el-tabs class="pt-2" v-model="activeName">

			<el-tab-pane :label="$t('system.system.info')" name="system">
				<System v-if="activeName == 'system'" ref="refsystem" @infoData="expose" />
			</el-tab-pane>

			<el-tab-pane :label="$t('system.system.Message')" name="Message" v-if="false">
				<Message v-if="activeName == 'Message'" ref="refmessage" @infoData="expose" />
			</el-tab-pane>

			<el-tab-pane :label="$t('system.system.Agree')" name="Agreement" v-if="false">
				<Agreement v-if="activeName == 'Agreement'" ref="refagreement" @infoData="expose" />
			</el-tab-pane>

			<el-tab-pane :label="$t('system.system.SMSconfig')" name="Sms" v-if="false">
				<Sms v-if="activeName == 'Sms'" ref="refsms" @infoData="expose" />
			</el-tab-pane>

			<el-tab-pane :label="$t('system.system.deviceKey')" name="Secret" v-if="false">
				<Secret v-if="activeName == 'Secret'" ref="refsecret" @infoData="expose" />
			</el-tab-pane>

			<el-tab-pane :label="$t('system.system.map')" name="Baidu" v-if="false">
				<Baidu v-if="activeName == 'Baidu'" ref="refbmapkey" @infoData="expose" />
			</el-tab-pane>

			<el-tab-pane :label="$t('system.system.Identity')" name="Identity" v-if="false">
				<Identity v-if="activeName == 'Identity'" ref="refidentity" @infoData="expose" />
			</el-tab-pane>

			<el-tab-pane :label="$t('system.system.safety')" name="secure">
				<Secure v-if="activeName == 'secure'" @infoData="expose" />
			</el-tab-pane>

		</el-tabs>

	</div>
</template>

<script lang="ts" setup>
import { useI18n } from 'vue-i18n'
const { t: $t } = useI18n()
import useUserStore from '@/store/user'
import { addconfig, updateconfig } from '@/api/system';
// 顶部信息
import TopInfo from '@/components/TopInfo/index.vue';
import System from '../Common/System.vue';
import Message from '../Common/Message.vue';
import Agreement from '../Common/Agreement.vue';
import Sms from '../Common/Sms.vue';
import Secret from '../Common/Secret.vue';
import Baidu from '../Common/Baidu.vue';
import Identity from '../Common/Identity.vue';
import Secure from '../Common/Secure.vue';
let activeName = 'system'
// ElLoading.service(options)

let expose = (e) => {
	let { name } = useUserStore()
	if (e.config_id == undefined) {
		// 添加
		add(e, name.manager_id)
	} else {
		// 修改
		update(e)
	}
}

// 添加
let add = (e, k) => {
	e.csr_id = k
	addconfig(e).then(res => {
		if (res.state == 200) {
			ElMessage({
				message: $t('message.addSuccess'),
				type: 'success'
			})
			getdata(e.config_name)
		} else {
			ElMessage({
				message: $t('message.networkFailed'),
				type: 'error'
			})
		}
	}).catch(err => {
		ElMessage({
			message: $t('message.networkFailed'),
			type: 'error'
		})
	})
}

// 修改
let update = (e) => {
	updateconfig(e).then(res => {
		if (res.state == 200) {
			ElMessage({
				message: $t('message.modifySuccess'),
				type: 'success'
			})
			getdata(e.config_name)
			window.location.reload()
		} else {
			ElMessage({
				message: $t('message.networkFailed'),
				type: 'error'
			})
		}
	}).catch(err => {
		ElMessage({
			message: $t('message.networkFailed'),
			type: 'error'
		})
	})
}

let refsystem = ref<any>() //系统信息
let refmessage = ref<any>() // 消息模板
let refagreement = ref<any>() // 用户协议
let refsms = ref<any>() // 短信配置
let refsecret = ref<any>() // 设备密钥
let refbmapkey = ref<any>() // 百度地图
let refidentity = ref<any>() // 身份证认证

// 获取管理
let getdata = (e) => {
	switch (e) {
		case 'systemInfo':
			// 调用子组件方法
			refsystem.value.getsystem()
			break;
		case 'tempKey':
			// 调用子组件方法
			refmessage.value.getmessage()
			break;
		case 'userAgreement':
			// 调用子组件方法
			refagreement.value.getagreement()
			break;
		case 'SMS':
			// 调用子组件方法
			refsms.value.getMsM()
			break;
		case 'machineKey':
			// 调用子组件方法
			refsecret.value.getmachineKey()
			break;
		case 'BMapKey':
			// 调用子组件方法
			refbmapkey.value.getBMapKey()
			break;
		case 'aliVerifyIdName':
			// 调用子组件方法
			refidentity.value.getaliVer()
			break;
	}
}



</script>
